#include <Measure.h>
#include <iostream>

using namespace std;

Measure::Measure(const unsigned int amount, const Unit unit) :
	amount_m(amount),
	unit_m(unit)
{
}

void Measure::print() const
{
	cout << amount_m << " " << unit_m << " = ";
}

void Measure::print(const Unit unit)
{
	cout << toBase() / unit.getToBaseRatio() << " " << unit << endl;
}

unsigned int Measure::toBase() const
{
	return amount_m * unit_m.getToBaseRatio();
}

void Measure::formatPrint(const Unit * unitArray, const unsigned int arrayLength)
{
	int i = arrayLength;
	unsigned int divisor = toBase();
	unsigned int com = toBase();

	for (i-=1; i>=0; i--)
	{
		divisor = com / unitArray[i].getToBaseRatio();
		com = com % unitArray[i].getToBaseRatio();
		if(divisor > 0)
		{
			cout << divisor << " " << unitArray[i] << " ";
		}
		if(com == 0)
			break;
	}
	cout << endl;
}
